<?php

namespace App\Http\Middleware;

use Closure;

class Cors
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {

        //这样应该是能过来的

//        return response('', 200)->header('Access-Control-Allow-Origin', '*');


        if ($request->isMethod('OPTIONS'))
        {
            return response('', 200)
            ->header('Access-Control-Allow-Methods', 'HEAD, GET, POST, PUT, PATCH, DELETE')
            ->header('Access-Control-Allow-Headers', $request->header('Access-Control-Request-Headers'))
            ;
        }


        return $next($request);
    }
}
